#ifndef __3D_VECTOR_CPP

#define __3D_VECTOR_CPP

#include "vect_3d.h"



//VECTOR

bool same_point(VECTOR dis, double Er) {

    if (fabs(dis.vect_x) < Er && fabs(dis.vect_y) < Er && fabs(dis.vect_z) < Er)

        return true;

    else return false;

};


VECTOR::VECTOR() {

    vect_x = 0.;

    vect_y = 0.;

    vect_z = 0.;

};

VECTOR::VECTOR(double x, double y, double z) {

    vect_x = x;

    vect_y = y;

    vect_z = z;


};

VECTOR VECTOR::operator=(const dvector& b) {

    vect_x = b.vect_x;

    vect_y = b.vect_y;

    vect_z = b.vect_z;

    return *this;

};


VECTOR VECTOR::operator+(const VECTOR& b) {

    double rx, ry, rz;

    rx = vect_x + b.vect_x;

    ry = vect_y + b.vect_y;

    rz = vect_z + b.vect_z;

    return (VECTOR(rx, ry, rz));

};

VECTOR VECTOR::operator-(const VECTOR& b) {

    double rx, ry, rz;

    rx = vect_x - b.vect_x;

    ry = vect_y - b.vect_y;

    rz = vect_z - b.vect_z;

    return (VECTOR(rx, ry, rz));

};

VECTOR VECTOR::operator-() {

    double rx, ry, rz;

    rx = -vect_x;

    ry = -vect_y;

    rz = -vect_z;

    return (VECTOR(rx, ry, rz));

};

double VECTOR::operator*(const VECTOR& b) {

    double temp;

    temp = vect_x * b.vect_x + vect_y * b.vect_y + vect_z * b.vect_z;

    return (temp);

};

VECTOR VECTOR::operator*(const double& b) {

    double rx, ry, rz;

    rx = vect_x * b;

    ry = vect_y * b;

    rz = vect_z * b;

    return (VECTOR(rx, ry, rz));

};

VECTOR VECTOR::operator/(const double& b) {

    double rx, ry, rz;

    rx = vect_x / b;

    ry = vect_y / b;

    rz = vect_z / b;

    return (VECTOR(rx, ry, rz));

};

VECTOR VECTOR::operator^(const VECTOR& b) {

    double rx, ry, rz;

    rx = vect_y * b.vect_z - vect_z * b.vect_y;

    ry = vect_z * b.vect_x - vect_x * b.vect_z;

    rz = vect_x * b.vect_y - vect_y * b.vect_x;

    return (VECTOR(rx, ry, rz));

};

void VECTOR::print() {

    cout << "\n(" << vect_x << "," << vect_y << "," << vect_z << ")";

};

void print(VECTOR& r_) {
    ofstream fo;
    fo.open("sysoutput", ios::ate);
    fo << r_.vect_x << "," << r_.vect_y << "," << r_.vect_z << "\n";
    fo.close();
}

double VECTOR::abs_vector() {

    return (sqrt(vect_x * vect_x + vect_y * vect_y

        + vect_z * vect_z));

};


VECTOR operator*(const double& a, const VECTOR& b) {

    VECTOR c;

    c.vect_x = a * b.vect_x;

    c.vect_y = a * b.vect_y;

    c.vect_z = a * b.vect_z;

    return (c);

}

double amp_R(VECTOR& r_, VECTOR& r1_) {

    double f;

    VECTOR a_;

    a_ = r_ - r1_;

    f = a_.abs_vector();

    return f;

}


double operator*(const dvector& a, const VECTOR& b) {

    double c;

    c = a.vect_x * b.vect_x + a.vect_y * b.vect_y + a.vect_z * b.vect_z;

    return c;

}

//dvector

bool same_point(dvector dis, double Er) {

    if (fabs(dis.vect_x) < Er && fabs(dis.vect_y) < Er && fabs(dis.vect_z) < Er)

        return true;

    else return false;

};

dvector::dvector() {

    vect_x = 0.;

    vect_y = 0.;

    vect_z = 0.;

};

dvector::dvector(double x, double y, double z) {

    vect_x = x;

    vect_y = y;

    vect_z = z;

};

dvector dvector::operator+(const dvector& b) {

    double rx, ry, rz;

    rx = vect_x + b.vect_x;

    ry = vect_y + b.vect_y;

    rz = vect_z + b.vect_z;

    return (dvector(rx, ry, rz));

};

dvector dvector::operator-(const dvector& b) {

    double rx, ry, rz;

    rx = vect_x - b.vect_x;

    ry = vect_y - b.vect_y;

    rz = vect_z - b.vect_z;

    return (dvector(rx, ry, rz));

};

dvector dvector::operator-() {

    double rx, ry, rz;

    rx = -vect_x;

    ry = -vect_y;

    rz = -vect_z;

    return (dvector(rx, ry, rz));

};

double dvector::operator*(const dvector& b) {

    double temp;

    temp = vect_x * b.vect_x + vect_y * b.vect_y + vect_z * b.vect_z;

    return (temp);

};

dvector dvector::operator*(const double& b) {

    double rx, ry, rz;

    rx = vect_x * b;

    ry = vect_y * b;

    rz = vect_z * b;

    return (dvector(rx, ry, rz));

};

dvector dvector::operator/(const double& b) {

    double rx, ry, rz;

    rx = vect_x / b;

    ry = vect_y / b;

    rz = vect_z / b;

    return (dvector(rx, ry, rz));

};

dvector dvector::operator^(const dvector& b) {

    double rx, ry, rz;

    rx = vect_y * b.vect_z - vect_z * b.vect_y;

    ry = vect_z * b.vect_x - vect_x * b.vect_z;

    rz = vect_x * b.vect_y - vect_y * b.vect_x;

    return (dvector(rx, ry, rz));

};

void dvector::print() {

    cout << "\n(" << vect_x << "," << vect_y << "," << vect_z << ")";

};

void print(dvector& r_) {
    ofstream fo;
    fo.open("sysoutput", ios::ate);
    fo << r_.vect_x << "," << r_.vect_y << "," << r_.vect_z << "\n";
    fo.close();
}

double dvector::abs_vector() {

    return (sqrt(vect_x * vect_x + vect_y * vect_y

        + vect_z * vect_z));

};


dvector operator*(const double& a, const dvector& b) {

    dvector c;

    c.vect_x = a * b.vect_x;

    c.vect_y = a * b.vect_y;

    c.vect_z = a * b.vect_z;

    return (c);

}


double amp_R(dvector& r_, dvector& r1_) {

    double f;

    dvector a_;

    a_ = r_ - r1_;

    f = a_.abs_vector();

    return f;

}

void v_to_dv(dvector& b, VECTOR& a) {

    b.vect_x = a.vect_x;

    b.vect_y = a.vect_y;

    b.vect_z = a.vect_z;

}



//Complex VECTOR

cvector::cvector() {

    vect_x = Complex(0);

    vect_y = Complex(0);

    vect_z = Complex(0);

};

cvector::cvector(Complex x, Complex y, Complex z) {

    vect_x = x;

    vect_y = y;

    vect_z = z;

};

cvector cvector::operator+(const cvector& b) {

    Complex rx, ry, rz;

    rx = vect_x + b.vect_x;

    ry = vect_y + b.vect_y;

    rz = vect_z + b.vect_z;

    return (cvector(rx, ry, rz));

};

cvector cvector::operator-(const cvector& b) {

    Complex rx, ry, rz;

    rx = vect_x - b.vect_x;

    ry = vect_y - b.vect_y;

    rz = vect_z - b.vect_z;

    return (cvector(rx, ry, rz));

};

cvector cvector::operator-() {

    Complex rx, ry, rz;

    rx = -vect_x;

    ry = -vect_y;

    rz = -vect_z;

    return (cvector(rx, ry, rz));

};

Complex cvector::operator*(const cvector& b) {

    Complex temp;

    temp = vect_x * b.vect_x + vect_y * b.vect_y + vect_z * b.vect_z;

    return (temp);

};

cvector cvector::operator*(const Complex& b) {

    Complex rx, ry, rz;

    rx = vect_x * b;

    ry = vect_y * b;

    rz = vect_z * b;

    return (cvector(rx, ry, rz));

};

cvector cvector::operator/(const Complex& b) {

    Complex rx, ry, rz;

    rx = vect_x / b;

    ry = vect_y / b;

    rz = vect_z / b;

    return (cvector(rx, ry, rz));

};

cvector cvector::operator^(const cvector& b) {

    Complex rx, ry, rz;

    rx = vect_y * b.vect_z - vect_z * b.vect_y;

    ry = vect_z * b.vect_x - vect_x * b.vect_z;

    rz = vect_x * b.vect_y - vect_y * b.vect_x;

    return (cvector(rx, ry, rz));

};

cvector cvector::operator^(const VECTOR& b) {

    Complex rx, ry, rz;

    rx = vect_y * b.vect_z - vect_z * b.vect_y;

    ry = vect_z * b.vect_x - vect_x * b.vect_z;

    rz = vect_x * b.vect_y - vect_y * b.vect_x;

    return (cvector(rx, ry, rz));

};

cvector operator^(const VECTOR& a, const cvector& b) {

    Complex rx, ry, rz;

    rx = a.vect_y * b.vect_z - a.vect_z * b.vect_y;

    ry = a.vect_z * b.vect_x - a.vect_x * b.vect_z;

    rz = a.vect_x * b.vect_y - a.vect_y * b.vect_x;

    return (cvector(rx, ry, rz));

};

void cvector::print() {

    cout << "(" << vect_x << "," << vect_y << "," << vect_z << ")";

};

double cvector::abs_cvector() {

    cvector a;

    a = conjugate(*this);

    return (sqrt(abs(a * (*this))));

}

cvector operator*(const VECTOR& a, const Complex& b) {

    cvector v;

    v.vect_x = a.vect_x * b;

    v.vect_y = a.vect_y * b;

    v.vect_z = a.vect_z * b;

    return (v);

}

cvector operator*(const Complex& b, const VECTOR& a) {

    cvector v;

    v.vect_x = a.vect_x * b;

    v.vect_y = a.vect_y * b;

    v.vect_z = a.vect_z * b;

    return (v);

}

cvector operator*(const Complex& b, const dvector& a) {

    cvector v;

    v.vect_x = a.vect_x * b;

    v.vect_y = a.vect_y * b;

    v.vect_z = a.vect_z * b;

    return (v);

}

cvector operator*(const dvector& a, const Complex& b) {

    cvector v;

    v.vect_x = a.vect_x * b;

    v.vect_y = a.vect_y * b;

    v.vect_z = a.vect_z * b;

    return (v);

}

cvector operator*(const Complex& b, const cvector& a) {

    cvector v;

    v.vect_x = a.vect_x * b;

    v.vect_y = a.vect_y * b;

    v.vect_z = a.vect_z * b;

    return (v);

}

cvector conjugate(const cvector& a) {

    cvector b;

    b.vect_x = conj(a.vect_x);

    b.vect_y = conj(a.vect_y);

    b.vect_z = conj(a.vect_z);

    return (b);

}

Complex operator*(const cvector& a, const VECTOR& b) {

    Complex c;

    c = a.vect_x * b.vect_x + a.vect_y * b.vect_y + a.vect_z * b.vect_z;

    return c;

}

Complex operator*(const VECTOR& a, const cvector& b) {

    Complex c;

    c = a.vect_x * b.vect_x + a.vect_y * b.vect_y + a.vect_z * b.vect_z;

    return c;

}

cvector operator-(const cvector& a, const VECTOR& b) {

    cvector c;

    c.vect_x = a.vect_x - b.vect_x;

    c.vect_y = a.vect_y - b.vect_y;

    c.vect_z = a.vect_z - b.vect_z;

    return c;

}

cvector operator-(const VECTOR& a, const cvector& b) {

    cvector c;

    c.vect_x = a.vect_x - b.vect_x;

    c.vect_y = a.vect_y - b.vect_y;

    c.vect_z = a.vect_z - b.vect_z;

    return c;

}

cvector operator+(const cvector& a, const VECTOR& b) {

    cvector c;

    c.vect_x = a.vect_x + b.vect_x;

    c.vect_y = a.vect_y + b.vect_y;

    c.vect_z = a.vect_z + b.vect_z;

    return c;

}

cvector operator+(const cvector& a, const cvector& b) {

    cvector c;

    c.vect_x = a.vect_x + b.vect_x;

    c.vect_y = a.vect_y + b.vect_y;

    c.vect_z = a.vect_z + b.vect_z;

    return c;

}


Complex operator*(const cvector& a, const dvector& b) {

    Complex c;

    c = a.vect_x * b.vect_x + a.vect_y * b.vect_y + a.vect_z * b.vect_z;

    return c;

}

Complex operator*(const dvector& a, const cvector& b) {

    Complex c;

    c = a.vect_x * b.vect_x + a.vect_y * b.vect_y + a.vect_z * b.vect_z;

    return c;

}

cvector operator-(const cvector& a, const dvector& b) {

    cvector c;

    c.vect_x = a.vect_x - b.vect_x;

    c.vect_y = a.vect_y - b.vect_y;

    c.vect_z = a.vect_z - b.vect_z;

    return c;

}

cvector operator-(const dvector& a, const cvector& b) {

    cvector c;

    c.vect_x = a.vect_x - b.vect_x;

    c.vect_y = a.vect_y - b.vect_y;

    c.vect_z = a.vect_z - b.vect_z;

    return c;

}

cvector operator+(const cvector& a, const dvector& b) {

    cvector c;

    c.vect_x = a.vect_x + b.vect_x;

    c.vect_y = a.vect_y + b.vect_y;

    c.vect_z = a.vect_z + b.vect_z;

    return c;

}


/*cvector operator/(const cvector &a,const Complex &b)

{

    cvector c;

   c.vect_x=a.vect_x/b;

   c.vect_y=a.vect_y/b;

   c.vect_z=a.vect_z/b;

    return c;

}

cvector operator/(const cvector &a,const double &b)

{

    cvector c;

   c.vect_x=a.vect_x/b;

   c.vect_y=a.vect_y/b;

   c.vect_z=a.vect_z/b;

    return c;

}

cvector operator*(const cvector &a,const Complex &b)

{

    cvector c;

   c.vect_x=a.vect_x*b;

   c.vect_y=a.vect_y*b;

   c.vect_z=a.vect_z*b;

    return c;

}

cvector operator*(const cvector &a,const double &b)

{

    cvector c;

   c.vect_x=a.vect_x*b;

   c.vect_y=a.vect_y*b;

   c.vect_z=a.vect_z*b;

    return c;

}

cvector operator*(const Complex &b,const cvector &a)

{

    cvector c;

   c.vect_x=a.vect_x*b;

   c.vect_y=a.vect_y*b;

   c.vect_z=a.vect_z*b;

    return c;

}

cvector operator*(const double &b,const cvector &a)

{

    cvector c;

   c.vect_x=a.vect_x*b;

   c.vect_y=a.vect_y*b;

   c.vect_z=a.vect_z*b;

    return c;

}  */

VECTOR real(cvector& a) {

    VECTOR b;

    b.vect_x = real(a.vect_x);

    b.vect_y = real(a.vect_y);

    b.vect_z = real(a.vect_z);

    return b;

};

VECTOR imag(cvector& a) {

    VECTOR b;

    b.vect_x = imag(a.vect_x);

    b.vect_y = imag(a.vect_y);

    b.vect_z = imag(a.vect_z);

    return b;

};

void sysout(char* a, cvector& b) {
    ofstream fo;
    fo.open("sysoutput", ios::ate);
    fo << a << b.vect_x << "," << b.vect_y << "," << b.vect_z;
    fo.close();
}

void sysout(char* a, VECTOR& b) {
    ofstream fo;
    fo.open("sysoutput", ios::ate);
    fo << a << b.vect_x << "," << b.vect_y << "," << b.vect_z;
    fo.close();
}

#endif